

#ifndef UD_DBIDMAP_H
#define UD_DBIDMAP_H 1

#include "zacdb.h"
#include "zrxobject.h"

#pragma pack (push, 8)

class UcDbDatabase;

class UcDbIdPair
{
public:
    UcDbIdPair();
    UcDbIdPair(const UcDbIdPair&);
    UcDbIdPair(UcDbObjectId key, UcDbObjectId value,
               bool isCloned,
               bool isPrimary = false,
               bool isOwnerXlated = true);

    UcDbObjectId   key() const;
    UcDbObjectId   value() const;
    bool           isCloned() const;
    bool           isPrimary() const;
    bool           isOwnerXlated() const;

    void 	   setKey(UcDbObjectId);
    void	   setValue(UcDbObjectId);
    void	   setIsCloned(bool isCloned);
    void	   setIsPrimary(bool isPrimary);
    void	   setIsOwnerXlated(bool isOwnerXlated);

private:
    UcDbObjectId   mKey;
    UcDbObjectId   mValue;
    bool           mIsCloned : 1;
    bool           mIsPrimary : 1;
    bool           mIsOwnerXlated : 1;
};

class UcDbIdMappingIter;
class UcDbImpIdMapping;
class UcDbImpIdMappingIter;

class UcDbIdMapping: public  UcRxObject
{
public:
    UcDbIdMapping();
    virtual ~UcDbIdMapping();
    UCRX_DECLARE_MEMBERS(UcDbIdMapping);

    virtual Ucad::ErrorStatus		assign(const UcDbIdPair&);
    virtual bool          		compute(UcDbIdPair&) const;
    virtual bool                        change(const UcDbIdPair&);
    virtual bool              		del(UcDbObjectId key);

	    Ucad::ErrorStatus   destDb(UcDbDatabase*& db) const;
	    Ucad::ErrorStatus   setDestDb(UcDbDatabase* db);
	    Ucad::ErrorStatus   origDb(UcDbDatabase*& db) const;

	    UcDb::DeepCloneType deepCloneContext() const;
            UcDb::DuplicateRecordCloning duplicateRecordCloning() const;

    virtual Ucad::ErrorStatus   copyFrom(const UcRxObject* other);

private:
    friend class UcDbSystemInternals;
    friend class UcDbImpIdMappingIter;
    UcDbIdMapping(const UcDbIdMapping&);
    UcDbIdMapping& operator= (const UcDbIdMapping&);
    UcDbImpIdMapping* mpImp;
};

class UcDbIdMappingIter: public  UcRxObject
{
public:
    UCRX_DECLARE_MEMBERS(UcDbIdMappingIter);
    UcDbIdMappingIter(const UcDbIdMapping&);
    virtual ~UcDbIdMappingIter();

    virtual Ucad::ErrorStatus	iterateOn(const UcDbIdMapping&);

    virtual void		start();
    virtual bool           	getMap(UcDbIdPair&);
    virtual bool           	next();
    virtual bool          	done();

private:
    friend class		UcDbSystemInternals;
    UcDbImpIdMappingIter*	mpImp;
};

inline
UcDbObjectId UcDbIdPair::key() const
{ return mKey; }

inline
UcDbObjectId UcDbIdPair::value() const
{ return mValue; }

inline
bool UcDbIdPair::isCloned() const
{ return mIsCloned; }

inline
bool UcDbIdPair::isPrimary() const
{ return mIsPrimary; }

inline
bool UcDbIdPair::isOwnerXlated() const
{ return mIsOwnerXlated; }

inline
void UcDbIdPair::setKey(UcDbObjectId key)
{ mKey = key; }

inline
void UcDbIdPair::setValue(UcDbObjectId value)
{ mValue = value; }

inline
void UcDbIdPair::setIsCloned(bool isCloned)
{ mIsCloned = isCloned; }

inline
void UcDbIdPair::setIsPrimary(bool isPrimary)
{ mIsPrimary = isPrimary; }

inline
void UcDbIdPair::setIsOwnerXlated(bool isOwnerXlated)
{ mIsOwnerXlated = isOwnerXlated; }

#pragma pack (pop)

#endif

